<?php
/**
 * Created by PhpStorm.
 * User: ewen
 * Date: 2019-09-02
 * Time: 16:41
 */

namespace app\api\controller;


use think\Cookie;
use think\Lang;

class GetLang
{

    public function get_lang()
    {
        $lang = null;
        if (input('?lang')) {
            $lang = input('lang');
        }
        if ($lang == null) {
            if (Cookie::has('think_var')) {
                $lang = Cookie::get('think_var');
            } else {
                $lang = 'zh-cn';
            }
        }
        $lang = Lang::range($lang);//设定当前语言
        Lang::load(APP_PATH . 'lang' . DS . $lang . EXT, $lang);//加载当前语言包
        Cookie::set('think_var', $lang);
        return $lang;
    }

}